package com.health.tablebean.webservice;

import android.content.Context;
import android.text.TextUtils;


import com.health.db.FDbManager;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.tablebean.CHILD_TCMHM_THREE2SIX;
import com.health.tablebean.CHILD_THREE2SIX_YEAR_OLD;
import com.health.viewscontrols.NovaApplication;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * 3--6岁儿童家庭访视实体类
 *
 * @author wangxiangyi
 * @date 2018/4/16
 */
public class YearChildHomeVisit {
    /**
     * 儿童体重的测量值，计量单位为kg
     */
    private String avoirdupois;
    /**
     * 随访日期
     */
    private String visitDate;
    /**
     * 年龄别体重评价结果代码，
     * DM01-39_1 上，
     * DM01-39_2 中，
     * DM01-39_3 下
     */
    private String ageAvoirdupois;
    /**
     * 身长(cm)
     */
    private String stature;
    /**
     * 年龄别身高评价结果代码，
     * DM01-39_1 上，
     * DM01-39_2 中，
     * DM01-39_3 下
     */
    private String ageStature;
    /**
     * 胸部听诊检查结果
     * DM01-40_1 未见异常，
     * DM01-40_2 异常
     */
    private String heartCheck;
    /**
     * 腹部触诊检查结果
     * DM01-40_1 未见异常，
     * DM01-40_2 异常
     */
    private String bellyCheck;
    /**
     * 3岁发育评估
     * DM05-26_8_1	不会说自己的名字，
     * DM05-26_8_2	不会玩“拿棍当马骑”等假想游戏，
     * DM05-26_8_3	不会模仿画圆，
     * DM05-26_8_4	不会双脚跳
     * <br><br>
     * 4岁发育评估
     * DM05-26_9_1	不会说带形容词的句子
     * DM05-26_9_2	不能按要求等待或轮流
     * DM05-26_9_3	不会独立穿衣
     * DM05-26_9_4	不会单脚站立
     * <br><br>
     * 5岁发育评估
     * DM05-26_10_1	不能简单叙说事情经过
     * DM05-26_10_2	不知道自己的性别
     * DM05-26_10_3	不会用筷子吃饭
     * DM05-26_10_4	不会单脚跳
     * <br><br>
     * 6岁发育评估
     * DM05-26_11_1	不会表达自己的感受或想法
     * DM05-26_11_2	不会玩角色扮演的集体游戏
     * DM05-26_11_3	不会画方形
     * DM05-26_11_4	不会奔跑
     */
    private String growthCheck;
    /**
     * 标识在对儿童进行两次随访之间是否有患病,
     * DM01-11_1 无，
     * DM01-11_2有
     */
    private String betweenVisitDisease;
    /**
     * 二次体检间肺炎次数
     */
    private String pneumoniaNum;
    /**
     * 二次体检间腹泻次数
     */
    private String diarrheaNum;
    /**
     * 二次体检间外伤次数
     */
    private String traumaNum;
    /**
     * 转诊原因、转诊机构及科室
     */
    private Rollout rollOut;
    /**
     * 其他疾病描述
     */
    private String otherDisease;
    /**
     * 转诊标志
     * DM01-11_1 无，
     * DM01-11_2有
     */
    private String outDiagnose;
    /**
     * 儿童健康指导类别代码
     * DM05-04_2	合理膳食，
     * DM05-04_3	生长发育，
     * DM05-04_4	疾病预防，
     * DM05-04_5	预防伤害，
     * DM05-04_6	口腔保健，
     * DM05-04_9	其他
     */
    private String childrenGuideType;
    /**
     * 指导其他
     */
    private String guideOther;
    /**
     * 下次随访日期
     */
    private String nextVisitDate;
    /**
     * 随访医生签名
     */
    private String reportDoctor;
    /**
     * 创建人
     */
    private String creater;
    /**
     * 创建机构
     */
    private String createorg;
    /**
     * 城乡居民健康档案编号
     */
    private String personalid;
    /**
     * 年龄（岁）
     * 1：3岁，
     * 2：4岁，
     * 3：5岁，
     * 4：6岁
     */
    private String age;
    /**
     * 完整度
     */
    private String wzd;
    /**
     * 乳牙萌出的数量，计量单位为颗
     */
    private String babyTeeth2;
    /**
     * 儿童龋齿的数量，计量单位为颗
     */
    private String babyTeeth3;
    /**
     * 中医药健康管理服务
     * DM200-04_1	中医饮食调养指导，
     * DM200-04_2	中医起居调摄指导，
     * DM200-04_3	传授摩腹、捏脊方法，
     * DM200-04_0	其他
     */
    private String res7;
    /**
     * 中医药健康管理服务其他
     */
    private String res8;
    /**
     * 单位容积血液中血红蛋白的含量值，计量单位为g／L
     */
    private String hgb;
    /**
     * 体格发育评价结果的代码组合
     * DM05-03_1	正常，
     * DM05-03_2	低体重，
     * DM05-03_3	消瘦，
     * DM05-03_4	生长迟缓，
     * DM05-03_5	超重
     */
    private String growthEvaluation;
    /**
     * 左耳听力,
     * DM01-30_1 通过，
     * DM01-30_2 未过
     */
    private String leftHearing;
    /**
     * 体格检查其他
     */
    private String otherCheck;
    /**
     * 体重/身高
     */
    private String res4;
    /**
     * 体重/身高评价结果代码,
     * DM01-39_1 上,
     * DM01-39_2 中，
     * DM01-39_3 下
     */
    private String res5;
    /**
     * 左眼裸眼远视力值
     */
    private String leftEyesight;
    /**
     * 右眼裸眼远视力值
     */
    private String rightEyesight;
    /**
     * 身份证（现做证件号码）
     */
    private String cardid;

    public String getAvoirdupois() {
        return avoirdupois;
    }

    public void setAvoirdupois(String avoirdupois) {
        this.avoirdupois = avoirdupois;
    }

    public String getVisitDate() {
        return visitDate;
    }

    public void setVisitDate(String visitDate) {
        this.visitDate = visitDate;
    }

    public String getAgeAvoirdupois() {
        return ageAvoirdupois;
    }

    public void setAgeAvoirdupois(String ageAvoirdupois) {
        this.ageAvoirdupois = ageAvoirdupois;
    }

    public String getStature() {
        return stature;
    }

    public void setStature(String stature) {
        this.stature = stature;
    }

    public String getAgeStature() {
        return ageStature;
    }

    public void setAgeStature(String ageStature) {
        this.ageStature = ageStature;
    }

    public String getHeartCheck() {
        return heartCheck;
    }

    public void setHeartCheck(String heartCheck) {
        this.heartCheck = heartCheck;
    }

    public String getBellyCheck() {
        return bellyCheck;
    }

    public void setBellyCheck(String bellyCheck) {
        this.bellyCheck = bellyCheck;
    }

    public String getGrowthCheck() {
        return growthCheck;
    }

    public void setGrowthCheck(String growthCheck) {
        this.growthCheck = growthCheck;
    }

    public String getBetweenVisitDisease() {
        return betweenVisitDisease;
    }

    public void setBetweenVisitDisease(String betweenVisitDisease) {
        this.betweenVisitDisease = betweenVisitDisease;
    }

    public String getPneumoniaNum() {
        return pneumoniaNum;
    }

    public void setPneumoniaNum(String pneumoniaNum) {
        this.pneumoniaNum = pneumoniaNum;
    }

    public String getDiarrheaNum() {
        return diarrheaNum;
    }

    public void setDiarrheaNum(String diarrheaNum) {
        this.diarrheaNum = diarrheaNum;
    }

    public String getTraumaNum() {
        return traumaNum;
    }

    public void setTraumaNum(String traumaNum) {
        this.traumaNum = traumaNum;
    }

    public Rollout getRollOut() {
        return rollOut;
    }

    public void setRollOut(Rollout rollOut) {
        this.rollOut = rollOut;
    }

    public String getOtherDisease() {
        return otherDisease;
    }

    public void setOtherDisease(String otherDisease) {
        this.otherDisease = otherDisease;
    }

    public String getOutDiagnose() {
        return outDiagnose;
    }

    public void setOutDiagnose(String outDiagnose) {
        this.outDiagnose = outDiagnose;
    }

    public String getChildrenGuideType() {
        return childrenGuideType;
    }

    public void setChildrenGuideType(String childrenGuideType) {
        this.childrenGuideType = childrenGuideType;
    }

    public String getGuideOther() {
        return guideOther;
    }

    public void setGuideOther(String guideOther) {
        this.guideOther = guideOther;
    }

    public String getNextVisitDate() {
        return nextVisitDate;
    }

    public void setNextVisitDate(String nextVisitDate) {
        this.nextVisitDate = nextVisitDate;
    }

    public String getReportDoctor() {
        return reportDoctor;
    }

    public void setReportDoctor(String reportDoctor) {
        this.reportDoctor = reportDoctor;
    }

    public String getCreater() {
        return creater;
    }

    public void setCreater(String creater) {
        this.creater = creater;
    }

    public String getCreateorg() {
        return createorg;
    }

    public void setCreateorg(String createorg) {
        this.createorg = createorg;
    }

    public String getPersonalid() {
        return personalid;
    }

    public void setPersonalid(String personalid) {
        this.personalid = personalid;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public String getWzd() {
        return wzd;
    }

    public void setWzd(String wzd) {
        this.wzd = wzd;
    }

    public String getBabyTeeth2() {
        return babyTeeth2;
    }

    public void setBabyTeeth2(String babyTeeth2) {
        this.babyTeeth2 = babyTeeth2;
    }

    public String getBabyTeeth3() {
        return babyTeeth3;
    }

    public void setBabyTeeth3(String babyTeeth3) {
        this.babyTeeth3 = babyTeeth3;
    }

    public String getRes7() {
        return res7;
    }

    public void setRes7(String res7) {
        this.res7 = res7;
    }

    public String getRes8() {
        return res8;
    }

    public void setRes8(String res8) {
        this.res8 = res8;
    }

    public String getHgb() {
        return hgb;
    }

    public void setHgb(String hgb) {
        this.hgb = hgb;
    }

    public String getGrowthEvaluation() {
        return growthEvaluation;
    }

    public void setGrowthEvaluation(String growthEvaluation) {
        this.growthEvaluation = growthEvaluation;
    }

    public String getLeftHearing() {
        return leftHearing;
    }

    public void setLeftHearing(String leftHearing) {
        this.leftHearing = leftHearing;
    }

    public String getOtherCheck() {
        return otherCheck;
    }

    public void setOtherCheck(String otherCheck) {
        this.otherCheck = otherCheck;
    }

    public String getRes4() {
        return res4;
    }

    public void setRes4(String res4) {
        this.res4 = res4;
    }

    public String getRes5() {
        return res5;
    }

    public void setRes5(String res5) {
        this.res5 = res5;
    }

    public String getLeftEyesight() {
        return leftEyesight;
    }

    public void setLeftEyesight(String leftEyesight) {
        this.leftEyesight = leftEyesight;
    }

    public String getRightEyesight() {
        return rightEyesight;
    }

    public void setRightEyesight(String rightEyesight) {
        this.rightEyesight = rightEyesight;
    }

    public String getCardid() {
        return cardid;
    }

    public void setCardid(String cardid) {
        this.cardid = cardid;
    }

    /**
     * 3--6岁内检查
     *
     * @param context 上下文
     * @param flag    3：3岁、
     *                4：4岁、
     *                5： 5岁、
     *                6： 6岁
     * @return
     */
    public static List<YearChildHomeVisit> convertData(Context context, String flag) {
        List<YearChildHomeVisit> datas = new ArrayList<>();

        FDbManager fdb = FDbManager.getInstance(context);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        List<CHILD_THREE2SIX_YEAR_OLD> infos = fdb.findAllByWhere(CHILD_THREE2SIX_YEAR_OLD.class,
                "IS_UPDATE is not 'N'" + " AND CREATER='" + NovaApplication.getJgrno() + "'AND FLAG='" + flag + "'");


        if (infos != null && !infos.isEmpty()) {
//            for (CHILD_THREE2SIX_YEAR_OLD info : infos) {
            CHILD_THREE2SIX_YEAR_OLD info = infos.get(infos.size() - 1);
            YearChildHomeVisit data = new YearChildHomeVisit();
            /* 3：3岁、4：4岁、 5：5岁、 6：6岁、*/
            if ("3".equals(flag)) {
                data.setAge(String.valueOf(Integer.parseInt(flag) * 12));
            } else if ("4".equals(flag)) {
                data.setAge(String.valueOf(Integer.parseInt(flag) * 12));
            } else if ("5".equals(flag)) {
                data.setAge(String.valueOf(Integer.parseInt(flag) * 12));
            } else if ("6".equals(flag)) {
                data.setAge(String.valueOf(Integer.parseInt(flag) * 12));
            }
            /*查询档案编号*/
            List<ARCHIVE_BASEINFO> baseinfos = fdb.findAllByWhere(ARCHIVE_BASEINFO.class,
                    "IDCARD ='" + info.getIDCARD() + "'");
            /*设置档案编号*/
            if (null != baseinfos && baseinfos.size() > 0) {
                data.setPersonalid(baseinfos.get(0).getARCHIVEID());
            } else {
                data.setPersonalid("");
            }
            /*身份证号*/
            data.setCardid(TextUtils.isEmpty(info.getIDCARD()) ? "" : info.getIDCARD().toUpperCase());
            /*随访日期*/
            if (info.getFOLLOWUP_DATE() != null) {
                data.setVisitDate(formatter.format(info.getFOLLOWUP_DATE()));
            }
            /*体重*/
            data.setAvoirdupois(TextUtils.isEmpty(info.getWEIGHT()) ? "" : info.getWEIGHT());
            /*体重分析*/
            data.setAgeAvoirdupois(TextUtils.isEmpty(info.getWEIGHT_ANALYSIS()) ? "" : info.getWEIGHT_ANALYSIS());
            /*身长*/
            data.setStature(TextUtils.isEmpty(info.getSTATURE()) ? "" : info.getSTATURE());
            /*身长评价*/
            data.setAgeStature(TextUtils.isEmpty(info.getSTATURE_ANALYSIS()) ? "" : info.getSTATURE_ANALYSIS());
            /*身长/体重*/
            data.setRes4(TextUtils.isEmpty(info.getSTATURE_WEIGHT()) ? "" : info.getSTATURE_WEIGHT());
            /*身长/体重评测*/
            data.setRes5(TextUtils.isEmpty(info.getSTATURE_WEIGHT_ANALYSIS()) ? "" : info.getSTATURE_WEIGHT_ANALYSIS());
            /*体重发育评价*/
            data.setGrowthEvaluation(TextUtils.isEmpty(info.getPHYSICAL_AUXE_EVALUAT()) ? "" : info.getPHYSICAL_AUXE_EVALUAT());
            /*视力左*/
            data.setLeftEyesight(TextUtils.isEmpty(info.getSIGHT()) ? "" : info.getSIGHT());
            /*视力右*/
            data.setRightEyesight(TextUtils.isEmpty(info.getSIGHT_RIGHT()) ? "" : info.getSIGHT_RIGHT());
            /*听力*/
            data.setLeftHearing(TextUtils.isEmpty(info.getLISTENING()) ? "" : info.getLISTENING());
            /*牙数量*/
            data.setBabyTeeth2(TextUtils.isEmpty(info.getTCN_LEFT()) ? "" : info.getTCN_LEFT());
            /*龋齿数量*/
            data.setBabyTeeth3(TextUtils.isEmpty(info.getTDCN_RIGHT()) ? "" : info.getTDCN_RIGHT());
            /*胸部*//*心肺 （4--6岁异常情况）*/
            data.setHeartCheck(TextUtils.isEmpty(info.getHEART_LUNG()) ? "" : info.getHEART_LUNG());
            /*腹部*/
            data.setBellyCheck(TextUtils.isEmpty(info.getSTOMACH()) ? "" : info.getSTOMACH());
            /*血红蛋白值*/
            data.setHgb(TextUtils.isEmpty(info.getHEMOGLOBIN_VALUE()) ? "" : info.getHEMOGLOBIN_VALUE());
            /*发育评估*/
            data.setGrowthCheck(TextUtils.isEmpty(info.getAUXE_ESTIMATE_OTHER()) ? "" : info.getAUXE_ESTIMATE_OTHER());
            /*两次随访间患者情况*/
            data.setBetweenVisitDisease(TextUtils.isEmpty(info.getAMONG_TWO_FOLLO_NONE()) ? "" : info.getAMONG_TWO_FOLLO_NONE());
            /*肺炎*/
            data.setPneumoniaNum(TextUtils.isEmpty(info.getPNEUMONIA_FREQUEN()) ? "" : info.getPNEUMONIA_FREQUEN());
            /*腹泻*/
            data.setDiarrheaNum(TextUtils.isEmpty(info.getDIARRHOEA_FREQUEN()) ? "" : info.getDIARRHOEA_FREQUEN());
            /*外伤*/
            data.setTraumaNum(TextUtils.isEmpty(info.getTRAUMATISM_FREQUEN()) ? "" : info.getTRAUMATISM_FREQUEN());
            /*其他*/
            data.setOtherDisease(TextUtils.isEmpty(info.getAMONG_TWO_FOLLO_OTHER()) ? "" : info.getAMONG_TWO_FOLLO_OTHER());
            /*转诊建议*/
            data.setOutDiagnose(TextUtils.isEmpty(info.getREFERRAL_ADVICE()) ? "" : info.getREFERRAL_ADVICE());
            /*转诊原因、机构及科室*/
            Rollout rollOut = new Rollout();
            rollOut.setHpc(TextUtils.isEmpty(info.getREFERRAL_REASON()) ? "" : info.getREFERRAL_REASON());
            rollOut.setRollInRegion(TextUtils.isEmpty(info.getAGENCIES_DEPARTMENTS()) ? "" : info.getAGENCIES_DEPARTMENTS());
            data.setRollOut(rollOut);
            /*指导*/
            data.setChildrenGuideType(TextUtils.isEmpty(info.getGUIDANCE()) ? "" : info.getGUIDANCE());
            /*指导其他原因*/
            data.setGuideOther(TextUtils.isEmpty(info.getGUIDANCE_OTHER()) ? "" : info.getGUIDANCE_OTHER());
            /*查询中医药管理服务（4--6没有中医药健康管理服务）*/
            List<CHILD_TCMHM_THREE2SIX> infos2 = fdb.findAllByWhere(CHILD_TCMHM_THREE2SIX.class,
                    "IDCARD='" + info.getIDCARD() + "'  AND FOLLOWUP_TYPE ='" + (Integer.parseInt(flag) - 2) + "'");
            /* 中医药健康管理服务*/
            if (null != infos2 && infos2.size() > 0) {
                /*中医药健康管理服务*/
                data.setRes7(infos2.get(0).getTCMHM());
                /*中医药健康管理服务其他原因*/
                data.setRes8(infos2.get(0).getTCMHM_OTHER());
            } else {
                /*中医药健康管理服务*/
                data.setRes7("");
                /*中医药健康管理服务其他原因*/
                data.setRes8("");
            }
            /*下次随访时间*/
            if (info.getNEXT_FOLLOWUP_DATE() != null) {
                data.setNextVisitDate(formatter.format(info.getNEXT_FOLLOWUP_DATE()));
            }
            /*随访医生签名*/
            data.setReportDoctor(TextUtils.isEmpty(info.getLAST_UPDATE_BY()) ? "" : info.getLAST_UPDATE_BY());
            /*创建人*/
            data.setCreater(TextUtils.isEmpty(info.getCREATER()) ? "" : info.getCREATER());
            /*创建机构*/
            data.setCreateorg(TextUtils.isEmpty(info.getCREATEORG()) ? "" : info.getCREATEORG());
            /*添加list里面*/
            datas.add(data);
        }
//        }
        return datas;
    }
}